package com.example.service.impl;

import com.example.demodao.entity.TbItem;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * VIP 用户的购物车
 * @author zhang
 */
@Slf4j
@Service(value = "VipUserCart")
public class VipUserCart extends NormalUserCart {  

    @Override  
    protected void processCouponPrice(long userId, TbItem item) {
        log.info("VIP 用户的购物车:{}，多买优惠策略。",userId);
        if (item.getQuantity() > 2) {  
            item.setCouponPrice(item.getPrice()  
                                // .multiply(BigDecimal.valueOf(100 - Db.getUserCouponPercent(userId)).divide(new BigDecimal("100")))
                                .multiply(BigDecimal.valueOf(100 - userId).divide(new BigDecimal("100")))
                                .multiply(BigDecimal.valueOf(item.getQuantity() - 2)));
        } else {  
            item.setCouponPrice(BigDecimal.ZERO);  
        }  
    }  
}  